﻿
using Dapper;
using HBase;
using System;
using System.Collections.Generic;
using System.Data;
namespace hCommand {
    public class WcsDeleteCraneAndCarrierTask :WcsBaseEngine {
        public long completeId;
        public int status;
        protected override TransRes Execute(IDbConnection connection ,IDbTransaction transaction) {
            List<Type> taskTypeList = PathFacade.getAllTaskType();
            foreach( Type device in taskTypeList ) {
                String tableName = ToStr.GetTableName(device);
                string sqlCrane = "select count(*) from " + tableName + "  where  status<>1  and complete_Id=@completeId";
                int count = connection.QueryUnique<int>(sqlCrane ,new { completeId = completeId } ,transaction);
                if( count != 0 ) {

                    return new TransRes(completeId + "的" + device + "任务状态不是待执行");

                }
            }
            foreach( Type device in taskTypeList ) {
                String tableName = ToStr.GetTableName(device);
                string sqlCrane = "update  " + tableName + " set status=-1  where complete_Id=@completeId";
                connection.Execute(sqlCrane ,new { completeId = completeId } ,transaction);

            }
            return new TransRes();
        }
    }
}
